/* 
 * Copyright (C) 2012 Martin Řehánek <rehan at mzk.cz>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

goog.provide('kramerius.audio.ui.test.PlaylistComponent');
//goog.require('goog.ui.Container');
//goog.require('goog.ui.Separator');
//goog.require('goog.events');
//goog.require('goog.ui.Component');
goog.require('goog.dom');
goog.require('goog.events');



//TODO: dedicnost
kramerius.audio.ui.test.PlaylistMenu = function(container, controller){
    this.container_ = container;
    
    //inicializace:
    
    //    var playlistContainer = new goog.ui.Container();
    //    playlistContainer.setId('Vertical Container');
    ////    goog.array.forEach(
    ////        ['Athos', 'Porthos', 'Aramis', 'd\'Artagnan'],
    ////        function(item) {
    ////            var c = new goog.ui.Control(item);
    ////            c.setId(item);
    ////            // For demo purposes, have controls dispatch transition events.
    ////            c.setDispatchTransitionEvents(goog.ui.Component.State.ALL, true);
    ////            playlistContainer.addChild(c, true);
    ////        });
    //    var firstItem = this.trackComponent("prvni", "deska");
    //    var secondItem = this.trackComponent("prvni", "deska");
    //    playlistContainer.addChild(firstItem);
    //    playlistContainer.addChild(secondItem);
    //    
    //    
    ////    playlistContainer.addChildAt(new goog.ui.Separator(), 3, true);
    ////    playlistContainer.getChild('Porthos').setEnabled(false);
    //    playlistContainer.render(container);
    //    

    // goog.events.listen(vc, EVENTS, logEvent);

    var listEl  = goog.dom.createDom('div',{
        'class':'playlist'    
    });
    container.appendChild(listEl);
    
    //var track = this.trackComponent("prvni", "prvni track");
    //console.log("appending " + track);
    listEl.appendChild(this.trackComponent("first", "prvni track"));
    listEl.appendChild(this.trackComponent("second", "druhy track"));
    listEl.appendChild(this.trackComponent("third", "treti track"));
    listEl.appendChild(this.trackComponent("fourth", "ctvrty track"));
    
}

//kramerius.audio.ui.test.PlaylistMenu.prototype.trackComponent = function(name, desc){
//    var trackContainer = new goog.ui.Container();
//    //container.setId('Vertical Container');
//    //goog.array.forEach(
//    //        ['Athos', 'Porthos', 'Aramis', 'd\'Artagnan'],
//    //        function(item) {
//    //            var c = new goog.ui.Control(item);
//    //            c.setId(item);
//    //            // For demo purposes, have controls dispatch transition events.
//    //            c.setDispatchTransitionEvents(goog.ui.Component.State.ALL, true);
//    //            container.addChild(c, true);
//    //        });
//    //var control1 = new goog.ui.Control(name);
//    trackContainer.addChild(new goog.ui.Control(name));
//    trackContainer.addChild(new goog.ui.Control("SPACE"));
//    trackContainer.addChild(new goog.ui.Control(desc));
//        
//    //container.addChildAt(new goog.ui.Separator(), 3, true);
//    //container.getChild('Porthos').setEnabled(false);
//    //container.render(goog.dom.getElement('vc'));
//    return trackContainer;
//}

kramerius.audio.ui.test.PlaylistMenu.prototype.trackComponent = function(title, desc){
    var root = goog.dom.createDom('div',{
        'class':'playlist-item'    
    });
    
    //nahoru
    var upEl = goog.dom.createDom('span',{
        'class':'playlist-item-up-enabled'    
    });
    //jeste se bude muset resit nejak pozice 
    //v opravdovem playlistu (seznam tracku pro player)
    goog.events.listen(upEl, goog.events.EventType.CLICK,
        function (e) {
            var brother = goog.dom.getPreviousElementSibling(root);
            goog.dom.insertSiblingBefore(root, brother);
        });
    root.appendChild(upEl);
    
    //dolu
    var downEl = goog.dom.createDom('span',{
        'class':'playlist-item-down-enabled'    
    });
    goog.events.listen(downEl, goog.events.EventType.CLICK,
        function (e) {
            var brother = goog.dom.getNextElementSibling(root);
            goog.dom.insertSiblingAfter(root, brother);
        });
    root.appendChild(downEl);
    
    //odstranit
    var removeEl = goog.dom.createDom('span',{
        'class':'playlist-item-remove'    
    });
    root.appendChild(removeEl);
    
    //nazev
    var titleEl = goog.dom.createDom('span',{
        'class':'playlist-item-title'    
    });
    titleEl.appendChild(document.createTextNode(title));
    root.appendChild(titleEl);
    
    //popis
    var descEl = goog.dom.createDom('span',{
        'class':'playlist-item-desc'    
    });
    goog.events.listen(descEl, goog.events.EventType.CLICK,
        function (e) {
            alert("clicked on description");
        });
    descEl.appendChild(document.createTextNode(desc));    
    root.appendChild(descEl);
       
    
    
    //nahoru:
    
       
        
        
    //sipka nahoru
   
    
    
    //    var descLink = goog.dom.createDom('a',{
    //        'href':'http://neco'    
    //    });
    //    descLink.appendChild(document.createTextNode(desc));
    //    descEl.appendChild(descLink);
    
    
    return root;
}

